package org.farng.mp3.id3;

import org.farng.mp3.InvalidTagException;
import org.farng.mp3.object.AbstractMP3Object;
import org.farng.mp3.object.ObjectGroupRepeated;
import org.farng.mp3.object.ObjectNumberFixedLength;
import org.farng.mp3.object.ObjectNumberHashMap;

import java.io.IOException;


/**
 * Title: Description: Copyright:    Copyright (c) 2002 Company:
 *
 * @author Eric Farng
 * @version $Revision: 1.3 $
 */
public class FrameBodyETCO extends AbstractID3v2FrameBody {
    /**
     * Creates a new FrameBodyETCO object.
     */
    public FrameBodyETCO() {
        //        this.setObject("Time Stamp Format", new Long(0));
        //        this.addGroup((byte) 0, (int) 0);
    }

    public FrameBodyETCO(FrameBodyETCO body) {
        super(body);
    }

    /**
     * Creates a new FrameBodyETCO object.
     *
     * @param timeStampFormat DOCUMENT ME!
     * @param event DOCUMENT ME!
     * @param timeStamp DOCUMENT ME!
     */
    public FrameBodyETCO(byte timeStampFormat, byte event, int timeStamp) {
        this.setObject("Time Stamp Format", new Long(timeStampFormat));
        this.addGroup(event, timeStamp);
    }

    /**
     * Creates a new FrameBodyETCO object.
     *
     * @param file DOCUMENT ME!
     *
     * @throws IOException DOCUMENT ME!
     * @throws InvalidTagException DOCUMENT ME!
     */
    public FrameBodyETCO(java.io.RandomAccessFile file)
                  throws IOException, InvalidTagException {
        this.read(file);
    }

    /**
     * DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public String getIdentifier() {
        return "ETCO" + ((char) 0) + getOwner();
    }

    /**
     * DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public String getOwner() {
        return (String) getObject("Owner");
    }

    /**
     * DOCUMENT ME!
     *
     * @param description DOCUMENT ME!
     */
    public void getOwner(String description) {
        setObject("Owner", description);
    }

    /**
     * DOCUMENT ME!
     *
     * @param event DOCUMENT ME!
     * @param timeStamp DOCUMENT ME!
     */
    public void addGroup(byte event, int timeStamp) {
        ObjectGroupRepeated group = (ObjectGroupRepeated) this.getObject("Data");
        AbstractMP3Object   ev = new ObjectNumberHashMap("Type Of Event", 1);
        AbstractMP3Object   ts = new ObjectNumberFixedLength("Time Stamp", 4);
        group.addObject(ev);
        group.addObject(ts);
        this.setObject("Data", group);
    }

    /**
     * DOCUMENT ME!
     */
    protected void setupObjectList() {
        objectList.add(new ObjectNumberHashMap("Time Stamp Format", 1));

        ObjectGroupRepeated group = new ObjectGroupRepeated("Data");
        group.addProperty(new ObjectNumberHashMap("Type Of Event", 1));
        group.addProperty(new ObjectNumberFixedLength("Time Stamp", 4));
        objectList.add(group);
    }
}